package scoreAnalyze;

import com.sun.org.apache.xml.internal.utils.IntVector;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.IntWritable;

import java.io.IOException;

public class DistributedReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
     public void reduce(Text key, Iterable<IntWritable> values, Context context)
                                throws IOException, InterruptedException
     {
         int a = 0, b = 0, c = 0, d = 0;
         for (IntWritable val : values){
             if (val.get() >= 90)
                 a++;
             else if(val.get() >= 80)
                 b++;
             else if(val.get() >= 60)
                 c++;
             else
                 d++;
         }
         context.write(new Text("参加" + key + "课程考试总人数："), new IntWritable(a + b + c + d));
         context.write(new Text("成绩90分以上的人数："), new IntWritable(a));
         context.write(new Text("成绩80分以上的人数："), new IntWritable(b));
         context.write(new Text("成绩60分以上的人数："), new IntWritable(c));
         context.write(new Text("成绩60分以下的人数："), new IntWritable(d));
     }
}
